import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
// 导入Vue Router的useRouter
import { useRouter } from 'vue-router'

export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const doubleCount = computed(() => count.value * 2)
  
  // 获取路由实例
  const router = useRouter()

  // 计数器自增方法
  function increment() {
    count.value++
  }
 
  async function goToGoods(id) {
    router.push({ name: 'Goods' , params: { id }})
  }

  async function goToClassify(id) {
    router.push({ name: 'ClassId' , params: { id }})
  }


  return { 
    count, 
    doubleCount, 
    increment,
    goToGoods,
    goToClassify
  }
})